<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<title>限时购列表</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/style.css" rel="stylesheet" />
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">限时购</h1>
		</header>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper transparent">
			<div class="mui-scroll">
				<ul class="mui-table-view mui-grid-view mui-clearfix vshop-product" id="productsList" style="margin-top: 10px;">
					
				</ul>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script src="js/delayimg.min.js"></script>
		<script>
			var isnodata = false,
				page = 1;
			mui.init({
				pullRefresh : {
				    container:'#pullrefresh',
				    deceleration:0.0006,
				    up : {
					    contentrefresh : "正在加载...",
					    contentnomore:'已加载全部限时购',
					    callback :function(){
					      	var self=this;
					      	if (!isnodata) {
					      		page++;
						        mui.ajax(URL+'api/LimitTimeBuy/GetLismitBuyList?pageNo='+page+'&pageSize=10',{
									dataType:'json',
									type:'get',
									timeout:10000,
									success:function(data){
										var html='';
					                    if(data.List.length>0){
											document.getElementById('productsList').insertAdjacentHTML('beforeend',initData(html,data));
											delayimg.render();
										}
					                    if (data.Total<=page*10) {isnodata = true;}
										self.endPullupToRefresh(isnodata);
									},
									error:function(xhr,type,errorThrown){
										plus.nativeUI.toast('请求失败，请检查网络')
									}
								});
						    }else{
						    	self.endPullupToRefresh(isnodata);
						    }
				    	}
				    }
				},
				swipeBack: true
			});
			mui.plusReady(function() {
				var ws=plus.webview.currentWebview();
				ws.setStyle({scrollIndicator:'none'});
				var w=plus.nativeUI.showWaiting('',{padlock:true});
				mui.ajax(URL+'api/LimitTimeBuy/GetLismitBuyList?pageNo=1&pageSize=10',{
					dataType:'json',
					type:'get',
					timeout:10000,
					success:function(data){
						var html='';
				        if (data.List.length > 0) {
				            document.getElementById('productsList').innerHTML=initData(html,data);
				            delayimg.init();
				            if (data.Total<10) {isnodata = true;}
				        }else{
				        	html+='<div class="empty-show"><h4>暂无任何限时购</h4><button id="closeWv" class="mui-btn mui-btn-negative">去其他地方逛逛</button></div>';
				        	document.getElementById('pullrefresh').innerHTML=html;
				        }
						w.close();
						document.getElementById('pullrefresh').className="mui-content mui-scroll-wrapper";
					},
					error:function(xhr,type,errorThrown){
						w.close();
						reloadWvLoad();
					}
				});
			});
			
			function initData(html,data){
				for(var i=0; i<data.List.length; i++){
					html+='<li class="mui-table-view-cell mui-media mui-col-xs-6">'+
            			'<div class="vshop-product-box">'+
							'<a data-id="'+data.List[i].ProductId+'">'+
								'<div class="p-img"><b data-delay-background="'+data.List[i].ProductImg+'"></b></div>'+
								'<div class="mui-media-body">'+data.List[i].ProductName+'</div>'+
								'<p class="vshop-product-price"><span>¥ '+data.List[i].MinPrice+'</span><em><i class="iconfont icon-time"></i>'+data.List[i].EndDate.substring(0,10)+'</em></p>'+
							'</a>'+
						'</div>'+
            		'</li>';
				}
				return html;
			}
			
			mui('#productsList').on('tap', 'a', function() {
				var id = this.getAttribute('data-id');
				showProduct(id);
			});
			
			
		</script>
	</body>

</html>